package com.yylending.las.authority.password;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.infrastructure.network.entity.EmptyEntity;
import com.yylending.las.Global;
import com.yylending.las.common.AESEntity;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Created by laixj on 2017/5/2.
 * Copyright ©2016 www.yylending.com. All Rights Reserved.
 */
public class ValidatePasswordModel extends Model {
	private static final String TAG = "LoginModel";

	public final static int METHOD_VALIDATE_PASSWORD = 1;

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class, 60);
		switch (functionalCode) {
			case METHOD_VALIDATE_PASSWORD:
				return service.validatePwd(Global.LOGIN_TOKEN, (AESEntity) params);
		}
		return null;
	}

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		BaseResultEntity result = cast(obj);
		switch (result.requestCode) {
			case METHOD_VALIDATE_PASSWORD:
				ValidatePwdResult validatePwdResult = cast(obj);
				EventAgent.post(validatePwdResult);
				break;
		}
	}

	private interface Service {
		/**
		 * 校验密码接口
		 */
		@POST("server/cuser/confirmPwd")
		Observable<ValidatePwdResult> validatePwd(@Header("token") String token, @Body AESEntity account);
	}

	static class ValidatePwdResult extends BaseResultEntity<EmptyEntity> {
	}

	public static class ValidatePassword {
		public String password;

		public ValidatePassword(String pwd) {
			password = pwd;
		}
	}

}